package com.gyq.shop.back.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gyq.shop.common.util.ConstatFinalUtil;
import com.gyq.shop.users.pojo.AAdmins;
/**
 * 
 * @author gyq
 *
 */
@Controller
@RequestMapping("/back/admins")
public class AdminsBackController
{
	/**
	 * 登陆后首页
	 * @return
	 */
	@RequestMapping("/main")
	public String main()
	{
		ConstatFinalUtil.LOGGER.info("=======main======");
		return "/back/main";
	}
	/**
	 * 退出
	 * @param request
	 * @param session
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/logout")
	public String logout(HttpServletRequest request,HttpSession session,HttpServletResponse response) throws IOException
	{
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		/* 处理当前服务的session */
		session.removeAttribute("admins");
		
		/* 还得操作用户中心 */
		/* 如何客户端跳转到用户中心退出的URL
		 * 如何在用户中心操作token
		 *  */
		
		/* 跳转到用户中心的登陆页面,并且将returnUrl带上去 */
		String usersCenterLogoutUrl = ConstatFinalUtil.BUNDLE.getString("users.center.logoutUrl") + "&token=" + admins.getToken();
		ConstatFinalUtil.LOGGER.info("--usersCenterLogoutUrl:{}",usersCenterLogoutUrl);
		/* 客户端跳转 */
		response.sendRedirect(usersCenterLogoutUrl);
		return null ; 
	}

}
